﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class admin_Typemng : System.Web.UI.Page
{
    MyDataDataContext db = new MyDataDataContext();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack && Session["AdminId"] != null)
        {
            var result = from r in db.GoodsType
                         select new
                         {
                             r.GoodsTypeID,
                             r.GoodsTypeName
                         };//映射需要显示的字段
            gv.DataSource = result;
            gv.DataBind();
        }
        else
        {
            Response.Redirect("../Login.aspx");
        }

    }
    protected void GridView2_OnRowCommang(object sender, GridViewCommandEventArgs e)
    {
        if (Session["AdminId"] == null)//用户未登录，返回登录界面
        {
            Response.Redirect("../Login.aspx");
        }
        else
        {
            if (e.CommandName != "Change") return;
            string id = e.CommandArgument.ToString();
            Response.Redirect("TypeCh.aspx?typeId=" + id);
        }
    }

    protected void Add(object sender, EventArgs e)
    {
        GoodsType goodtype = new GoodsType();
        goodtype.GoodsTypeID = AddId.Text.Trim();
        goodtype.GoodsTypeName = AddName.Text.Trim();
        db.GoodsType.InsertOnSubmit(goodtype);
        db.SubmitChanges();
        Response.Redirect("Typemng.aspx");
    }
}